package com.hz.monitoring.module.hardware.socket.ifwl_gprs_v2.handler;

import com.hz.monitoring.module.hardware.socket.util.BinHexOctUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * 16进制解码
 */

public class DecoderHandler extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
        //创建字节数组,buffer.readableBytes可读字节长度
        byte[] b = new byte[buffer.readableBytes()];
        //复制内容到字节数组b
        buffer.readBytes(b);

        System.out.println("原始字符串："+new String(b));
        String hexString = BinHexOctUtil.binaryToHexString(b);
        //加密内容转换
        hexString = hexString.replace("FDED", "FD").replace("FDEE", "FE");
        out.add(hexString);
    }

}